<%@ page import="ro.gateway.aida.srv.ICFService,
                 ro.gateway.aida.servlet.Constants,
                 ro.gateway.aida.srv.EditorServlet,
                 java.util.Hashtable,
                 ro.gateway.aida.srv.IIDGenerator,
                 ro.xblue.translator.TranslatorUtils,
                 ro.xblue.translator.LanguageBean,
                 ro.gateway.aida.usr.*,
                 ro.gateway.aida.utils.HttpUtils,
                 ro.gateway.aida.db.PersistenceToken,
                 ro.gateway.aida.utils.Utils,
                 ro.gateway.aida.db.PersistenceManager"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%
      PersistenceToken token = PersistenceManager.tokenLookup( application );
      User logged_user = UserUtils.getLogged(request);
      	Utils.setBreadCrumbs(request,"bc.users.list");
      if (!Arbiter.getManager(token).canDo(request, Perms.ADMIN_TOOLS)) {
            request.getRequestDispatcher("/frw.do?fw=norights").
                  forward(request, response);
            return;
      }

      String ctx = request.getContextPath();

      ICFService cfService = (ICFService) ((Hashtable) application.
            getAttribute(Constants.SERVICES)).get(Constants.SERVICE_CF);

      if (cfService == null) {
        response.sendError(
                HttpServletResponse.SC_EXPECTATION_FAILED, "cfService down.");
        return;
      }

	String sort_criteria = HttpUtils.getSortCriteria(request, "userlist_sortkey", "sort", "first_names");

	User[] users = null;
	try {
		users = UserDB.getManager(token).getAllArray(sort_criteria);
		if (users == null) users = new User[0];
	} catch (Exception ex) {
		ex.printStackTrace();
	}
//      System.out.println( "users.length:" + users.length );
%>
<trans:initPage module="users" />
<html>

<head>
    <title><trans:showPageMessage label="page.title" /></title>
<link rel="stylesheet" href="../alf.css" type="text/css">
</head>

<body>
 <jsp:include page="../header.jsp" />
<table border="0" cellpadding="5" align="center" width="75%" cellspacing="1" background=<%=ctx%>/images/pixelbgtable.gif class="text_search">
  <tr background=<%=ctx%>/images/pixelbgtable.gif>
    <td colspan="5" class="textalb"> <a href="<%=ctx%>/admin.jsp" class="textalb"><trans:showMessage module="admin" label="page.pagename" /></a> 
      :: <trans:showMessage module="admin" label="page.modusr" /> <trans:showPageMessage label="translator.showhiddentags"/></td>
  </tr>
  <% if (users.length == 0) { %>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="5" class="text_searchBold"> 
      <div align="center"><trans:showPageMessage label="page.noitems" /></div>
    </td>
  </tr>
  <% } else { %>
  <tr bgcolor="#FFFFFF" class="text_searchBold">
	<td class="text_searchBold"><div align="center">
		<a style="text-decoration:none;" href="users.jsp?sort=<%=sort_criteria.equals("login") ? "-" : ""%>login"><trans:showPageMessage label="page.login" /><% if (sort_criteria.endsWith("login")) { %>&nbsp;<%=sort_criteria.startsWith("-") ? "&uarr;" : "&darr;"%><% } %></a>
	</div></td>
	<td class="text_searchBold"><div align="center">
		<a style="text-decoration:none;" href="users.jsp?sort=<%=sort_criteria.equals("first_names") ? "-" : ""%>first_names"><trans:showPageMessage label="page.fnames" /><% if (sort_criteria.endsWith("first_names")) { %>&nbsp;<%=sort_criteria.startsWith("-") ? "&uarr;" : "&darr;"%><% } %></a>
	</div></td>
	<td class="text_searchBold"><div align="center">
		<a style="text-decoration:none;" href="users.jsp?sort=<%=sort_criteria.equals("last_name") ? "-" : ""%>last_name"><trans:showPageMessage label="page.lname" /><% if (sort_criteria.endsWith("last_name")) { %>&nbsp;<%=sort_criteria.startsWith("-") ? "&uarr;" : "&darr;"%><% } %></a>
	</div></td>
	<td class="text_searchBold"><div align="center">
		<a style="text-decoration:none;" href="users.jsp?sort=<%=sort_criteria.equals("email") ? "-" : ""%>email"><trans:showPageMessage label="page.email" /><% if (sort_criteria.endsWith("email")) { %>&nbsp;<%=sort_criteria.startsWith("-") ? "&uarr;" : "&darr;"%><% } %></a>
	</div></td>
	<td class="text_searchBold"><div align="center">
		<trans:showPageMessage label="page.options" />
	</div></td>
  </tr>
  <% for (int i = 0; i < users.length; i++) { %>
  <% if (users[i].isStandby()) { %>
  <tr bgcolor="#f2f2f2" title="<%=users[i].getLogin()%> : <trans:showPageMessage label="page.standby" />"> 
    <% } else { %>
  <tr bgcolor="#FFFFFF"> 
    <% } %>
    <td><%=users[i].getLogin()%></td>
    <td><%=users[i].getFirstNames()%></td>
    <td><%=users[i].getLastName()%></td>
    <td><%=users[i].getEmail()%></td>
    <td> <a href="<%=ctx%>/usr/uedit?<%=EditUserServlet.PNAME_ACTION%>=<%=EditUserServlet.PV_ACTION_EDIT%>&id=<%=users[i].getId()%>">[<trans:showPageMessage label="page.edit" />]</a> 
      <a href="<%=ctx%>/usr/uedit?<%=EditUserServlet.PNAME_ACTION%>=<%=EditUserServlet.PV_ACTION_DELETE%>&id=<%=users[i].getId()%>">[<trans:showPageMessage label="page.delete" />]</a> 
    </td>
  </tr>
  <% } %>
  <% } %>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="5"><a href="<%=ctx%>/usr/uedit?action=new"><trans:showPageMessage label="page.adduser" /></a></td>
  </tr>
</table>
<br><br>
	<jsp:include page="../footer.jsp" />
</body>
